use std::{net::TcpStream, io::Write, error::Error};

#[derive(Debug)]
pub struct Writer {
    inner: TcpStream,
}

impl Clone for Writer {
    fn clone(&self) -> Self {
        Self { inner: self.inner.try_clone().unwrap() }
    }
}

impl Writer {
    pub fn from(stream: &TcpStream) -> Self {
        Self { inner: stream.try_clone().unwrap() }
    }

    pub fn write(&mut self, bytes: &Vec<u8>) -> Result<(), Box<dyn Error>> {
        self.inner.write_all(bytes)?;
        Ok(())
    }
}